package 蓝桥._2024.商品库存管理;

import java.io.BufferedInputStream;
import java.util.Arrays;
import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改

public class Main2 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedInputStream(System.in));
        //在此输入您的代码...
        int n = scan.nextInt(); // 商品数量
        int m = scan.nextInt(); // 操作数量

        int[][] op = new int[m][2];
        // 区间加法：使用差分数组
        int[] diff = new int[n+3];
        int zero = 0;
        int[] c_1 = new int[n+1]; // 前i项中1的个数
        for (int i = 0; i < m; i++) {
            op[i][0] = scan.nextInt();
            op[i][1] = scan.nextInt();
            diff[op[i][0]] ++;
            diff[op[i][1]+1] --;
        }

        int[] stock = new int[n+1];
        for (int i = 1; i <= n; i++) {
            stock[i] = stock[i-1] + diff[i];
            c_1[i] = c_1[i-1];
            if(stock[i]==0) zero++;
            if(stock[i]==1) c_1[i]++;
        }
//        System.out.println(Arrays.toString(stock));
//        System.out.println(Arrays.toString(c_0));
//        System.out.println(Arrays.toString(c_1));
        int[] ans = new int[m];
        for (int i = 0; i < m; i++) {
            // 全部0的数量+区间内1的数量
            int t = zero +  (c_1[op[i][1]]-c_1[op[i][0]-1]);
            ans[i] = t;
        }
        for (int an : ans) {
            System.out.println(an);
        }
        scan.close();
    }
}